package com.qst.mapreduce.wordcount.zuoyemywc.taobao0;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class InfoReduce extends Reducer<App, Text,Text, App> {
    @Override
    protected void reduce(App key, Iterable<Text> values, Reducer<App, Text, Text, App>.Context context) throws IOException, InterruptedException {

        int count = 0;
        int tatolBrowseCount = 0;
        double tatolCTR = 0;
        for (Text app:values) {
            tatolBrowseCount += key.getBrowseCount();
            tatolCTR += key.getCTR();
            count++;

        }
        App outapp = new App();
        outapp.setBrowseCount(tatolBrowseCount / count);
        outapp.setCTR(tatolCTR / count);
        //context.write(value, outapp);
    }

}
